package com.mk.admin.service.impl;

import com.mk.admin.mapper.SurveyQuestionMapper;
import com.mk.admin.model.ResultDto;
import com.mk.admin.model.entity.SurveyQuestionEntity;
import com.mk.admin.model.vo.SurveyQuestionVo;
import com.mk.admin.service.SurveyQuestionService;
import com.mk.admin.util.JSONCopy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SurveyQuestionServiceImpl implements SurveyQuestionService {
    @Autowired
    private SurveyQuestionMapper surveyQuestionMapper;
    @Override
    public ResultDto add(SurveyQuestionVo surveyQuestionVo) {
        SurveyQuestionEntity entity = JSONCopy.copy(surveyQuestionVo, SurveyQuestionEntity.class);
        return ResultDto.data(surveyQuestionMapper.insert(entity));
    }

    @Override
    public ResultDto update(SurveyQuestionVo surveyQuestionVo) {
        SurveyQuestionEntity entity = JSONCopy.copy(surveyQuestionVo, SurveyQuestionEntity.class);
        return ResultDto.data(surveyQuestionMapper.updateById(entity));
    }

    @Override
    public ResultDto delete(int id) {
        return ResultDto.data(surveyQuestionMapper.deleteById(id));
    }

    @Override
    public ResultDto status(int id) {
        return ResultDto.data(surveyQuestionMapper.status(id));
    }

    @Override
    public ResultDto select(SurveyQuestionVo surveyQuestionVo) {
        SurveyQuestionEntity entity = JSONCopy.copy(surveyQuestionVo, SurveyQuestionEntity.class);
        return ResultDto.data(surveyQuestionMapper.count(entity),surveyQuestionMapper.select(entity));
    }
}
